<script setup lang="ts">
import { ref } from "vue";
import { artificialEntryConfig } from "./utils/hook";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { usePublicHooks } from "../../hooks";
import { usePublicFormats } from "../../formats";
import { PureTableBar } from "@/components/RePureTableBar";

import Refresh from "@iconify-icons/ep/refresh";
import AddFill from "@iconify-icons/ri/add-circle-line";

defineOptions({
  name: "artificialEntry"
});

const formRef = ref();
const { carColorOptions } = usePublicFormats();

const {
  columns,
  form,
  loading,
  onSearch,
  resetForm,
  dataList,
  pagination,
  onSizeChange,
  onCurrentChange,
  loadingConfig,
  openDialog,
  handleDelete
} = artificialEntryConfig();
</script>

<template>
  <div>
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
      :header-cell-style="{
        background: 'var(--el-fill-color-light)',
        color: 'var(--el-text-color-primary)'
      }"
    >
      <el-form-item label="车牌号" prop="car_number" class="!w-[20%]">
        <el-input
          v-model="form.car_number"
          placeholder="请输入车牌号"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item label="车牌颜色" prop="car_no_color" class="!w-[20%]">
        <el-select
          v-model="form.car_no_color"
          placeholder="请选择车牌颜色"
          clearable
        >
          <el-option
            v-for="item in carColorOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="停车场名称" prop="park_name" class="!w-[20%]">
        <el-input
          v-model="form.park_name"
          placeholder="请输入停车场名称"
          clearable
          class="!w-[160px]"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon('ri:search-line')"
          :loading="loading"
          @click="onSearch"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <PureTableBar title="入场操作" :columns="columns" @refresh="onSearch">
      <template #buttons>
        <el-button
          type="primary"
          :icon="useRenderIcon(AddFill)"
          @click="openDialog()"
        >
          新增
        </el-button>
      </template>
      <pure-table
        v-if="dataList.length > 0"
        ref="tableRef"
        stripe
        row-key="id"
        alignWhole="center"
        showOverflowTooltip
        :loading="loading"
        :loading-config="loadingConfig"
        :columns="columns"
        :data="dataList"
        :header-cell-style="{
          background: 'var(--el-fill-color-light)',
          color: 'var(--el-text-color-primary)'
        }"
        :pagination="pagination"
        @page-size-change="onSizeChange"
        @page-current-change="onCurrentChange"
      />
    </PureTableBar>
  </div>
</template>
